package com.htgd.gardenexpo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.dao.GeConIntegralGetDetailsDao;
import com.htgd.gardenexpo.entity.GeConIntegralGetDetails;
import com.htgd.gardenexpo.page.IntegralGetDetailsQuery;
import com.htgd.gardenexpo.page.PageBase;
import com.htgd.gardenexpo.service.GeConIntegralGetDetailsService;
import com.htgd.gardenexpo.utils.PhoneUtils;
import com.htgd.gardenexpo.utils.TokenUtil;
import com.htgd.gardenexpo.vo.IntegralDetailsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 获取详情 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-07-04
 */
@Service
public class GeConIntegralGetDetailsServiceImpl extends ServiceImpl<GeConIntegralGetDetailsDao, GeConIntegralGetDetails> implements GeConIntegralGetDetailsService {

    @Autowired
    private GeConIntegralGetDetailsDao geConIntegralGetDetailsDao;

    @Override
    public PageInfo<GeConIntegralGetDetails> querylist(IntegralGetDetailsQuery integralGetDetailsQuery, HttpServletRequest request) {
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        if(!PhoneUtils.confPhone(openId)){
            integralGetDetailsQuery.setOpenId(openId);
        }
        PageHelper.startPage(integralGetDetailsQuery.getPageNum(), integralGetDetailsQuery.getPageSize());
        List<GeConIntegralGetDetails> list = geConIntegralGetDetailsDao.querylist(integralGetDetailsQuery);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<IntegralDetailsVO> getIntegralDetails(String openId, PageBase pageBase) {
        PageHelper.startPage(pageBase.getPageNum(), pageBase.getPageSize());
        List<IntegralDetailsVO> list = geConIntegralGetDetailsDao.getIntegralDetails(openId);
        for (IntegralDetailsVO integralDetailsVO : list) {
            integralDetailsVO.setAmount("+"+integralDetailsVO.getAmount());
        }
        return new PageInfo<>(list);
    }
}
